package me.zhengjie.minbearwcs.dao.storage.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.storage.inf.MediumStorageDao;
import me.zhengjie.minbearwcs.entity.Mapper.storage.MediumStorageMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.storage.MediumStorage;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class MediumStorageDaoImpl implements MediumStorageDao {

    private final MediumStorageMapper mapper;

    @Override
    public boolean updateBatch1Info(String mediumSotrage, String inboundOrder, String material, String batch) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(MediumStorage::getMediumStorageCode, mediumSotrage)
                .set(MediumStorage::getInboundOrderOne, inboundOrder)
                .set(MediumStorage::getMaterialOne, material)
                .set(MediumStorage::getBatchOne, batch)
                .update();
    }

    @Override
    public boolean updateBatch2Info(String mediumSotrage, String inboundOrder, String material, String batch) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(MediumStorage::getMediumStorageCode, mediumSotrage)
                .set(MediumStorage::getInboundOrderTwo, inboundOrder)
                .set(MediumStorage::getMaterialTwo, material)
                .set(MediumStorage::getBatchTwo, batch)
                .update();
    }

    @Override
    public MediumStorage selectByMediumStorage(String mediumStorage) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(MediumStorage::getMediumStorageCode, mediumStorage)
                .oneOpt()
                .orElse(null);
    }

    @Override
    public boolean updateOutboundOrderByMediumStorage(String mediumStorage, String outboundOrderCode) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(MediumStorage::getMediumStorageCode, mediumStorage)
                .set(MediumStorage::getOutboundOrder, outboundOrderCode)
                .update();
    }

    @Override
    public boolean insert(MediumStorage mediumStorage) {
        return mapper.insert(mediumStorage) == 1;
    }

    @Override
    public boolean clear() {
        return mapper.delete(new QueryWrapper<>()) == 1;
    }
}
